<?php
namespace app\operator\controller;
use think\Db;

class User extends Common
{
	//获取系统信息
    public function getsysteminfo()
    {
    	
    	$oid  = input('param.oid');

        $info['systeminfo'] = Db::name('systeminfo')->where('id',1)->find();
        $info['operator'] = Db::name('operator')->where(['id'=>$oid,'is_delete'=>1])->field('id,name,create_user')->find();

        $admin = Db::name('admin')->where('id',$info['operator']['create_user'])->field('id,name,phone')->find();

        $info['systeminfo']['adminname'] = $admin['name'];
        $info['systeminfo']['phone'] = $admin['phone'];

        if($info['systeminfo']['logo']){
            $info['systeminfo']['logo'] = config('website').$info['systeminfo']['logo'];
        }
        if(!$info['operator'] ){
            $info['code'] = 0;
            $info['msg'] = '运营商信息错误！';
            return  $info;
        }else{
            $info['code'] = 1;
            return  $info;
        }
       
    }
    public function getusername(){

        $oid  = input('param.oid');
        $openid = mwdecrypt(input('param.openid'));

        //获取用户详情
        $info['user'] = Db::name('operator_users')
            ->where('oid',$oid)
            ->where('openid',$openid)
            ->find();
        if($info){
            $info['code'] = 1;
            return $info;
        }else{
            $info['code'] = 0;
            return $info;
        }

    }
    public function unbound(){

            $oid  = input('param.oid');
            $openid = mwdecrypt(input('param.openid'));

            //获取用户详情
            $status= Db::name('operator_users')
                ->where('oid',$oid)
                ->where('openid',$openid)
                ->update(['openid' => NULL]);


            if($status){
                $info['code'] = 1;
                return $info;
            }else{
                $info['code'] = 0;
                return $info;
            }

    }
}
